use crate::url::Url;
use std::fmt;
use std::fmt::Display;
use std::fmt::Formatter;
const NORMALPREFIX: &str = "//i0.hdslb.com/bfs/article/";
impl Url {
    fn auto_parse(string: String) -> Self {
        //https://i0.hdslb.com/bfs/article/
        if string.contains(NORMALPREFIX) {
            let name = string.split('/').last().unwrap().to_owned();
            Url::NormalPrefix(name)
        } else {
            Url::Special(string)
        }
    }
    pub fn as_string(&self) -> String {
        match self {
            Url::NormalPrefix(a) => format!("https:{}{}", NORMALPREFIX, a),
            Url::Special(b) => format!("https:{}", b),
        }
    }
    pub fn get_url_name(&self) -> String {
        self.as_string().split('/').last().unwrap().to_owned()
    }
    pub fn new(string: String) -> Self {
        Self::auto_parse(string)
    }
}
impl Display for Url {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.as_string())
    }
}
